{
 "cells": [
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "d2c76dec",
   "metadata": {},
   "source": [
    "# 模块glob：文件模式匹配\n",
    "\n",
    "glob模块是与文件模式匹配相关的标准库模块，提供了方便的文件模式匹配方法："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "a436b96b",
   "metadata": {},
   "outputs": [],
   "source": [
    "import glob"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "079a8c13",
   "metadata": {},
   "source": [
    "匹配当前文件夹下所有的.ipynb文件："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "021bb10c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['05-06模块glob：文件模式匹配.ipynb',\n",
       " '05-01模块sys：系统相关.ipynb',\n",
       " '05-02模块os：与操作系统进行交互.ipynb',\n",
       " '05-03模块re：正则表达式.ipynb',\n",
       " '05-05模块json：处理JSON数据.ipynb',\n",
       " '05-04模块datetime：日期时间.ipynb']"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "glob.glob(\"*.ipynb\")"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "32911217",
   "metadata": {},
   "source": [
    "一般来说，glob.glob()函数支持三种格式的语法：\n",
    "- “*”：匹配单个或多个字符，除了路径分隔符。\n",
    "- “?”：匹配任意单个字符。\n",
    "- “[seq]”：匹配指定范围内的单个字符，如：[0-9]匹配单个数字。\n",
    "- “[!seq]”：匹配非指定范围内的单个字符，如：[!0-9]匹配非数字的单个字符。\n",
    "- 如果要匹配“*”和“?”本身，可以使用“[*]”和“[?]”来转义。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4da11480",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
